home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10868 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.5 KB

  1. Path: binah.cc.brandeis.edu!DERNIS
  2. From: dernis@binah.cc.brandeis.edu
  3. Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++
  4. Subject: Re: C/C++ knocks the crap out of Ada
  5. Date: 11 Mar 1996 02:01:15 GMT
  6. Organization: Brandeis University
  7. Message-ID: <4i01hb$s6j@new-news.cc.brandeis.edu>
  8. References: <00001a73+00002504@msn.com> <1996Feb22.005518.13396@leeweyr.sccsi.com>    <4gvrffINNlqo@anvil.ugrad.cs.ubc.ca> <4h5hgj$vpd@tomquartz.niestu.com>    <4h7jskINNnph@anvil.ugrad.cs.ubc.ca> <313EDF38.61C1@lfwc.lockheed.com> <TANMOY.96Mar7180321@qcd.lanl.gov>
  9. Reply-To: dernis@binah.cc.brandeis.edu
  10. NNTP-Posting-Host: binah.cc.brandeis.edu
  11.  
  12. Sorry I lost the credit:
  13. >
  14. >To be precise, C standard declares all programs that violate array
  15. >bounds as illegal, but does not _require_ the compiler to check for
  16. >these violations. This is a change from pre-standard days when a
  17. >program was considered valid as long as it did not try to access
  18. >memory beyond what was allocated to it.
  19. >
  20. >As an example,
  21. >
  22. >char a2[100][100];
  23. >char *a = &a2[0][0];
  24. >
  25. >It is obvious from the constraints of memory layout for arrays and
  26. >pointer arithmetic, that a+200 would have pointed to a[2][0] if it
  27. >were valid. However, the standard has declared a+200 to invoke
  28. >undefined behaviour. Thus, a very strict bounds checking
  29. >implementation can reject such pointer arithmetic without violating
  30. >the standard.
  31.  
  32. It does little good to tell a programmer not to do
  33. something in the language standard when I bet most
  34. programmers have never read the ARM, and certainly
  35. do not keep up with the latest version.
  36.  
  37.  
  38. I have jus read a good deal of this thread.  Several people
  39. have made this argument to me that many languages not just
  40. ADA impose more (better?) structure, on the programmer.  Thus
  41. resulting in better reliability.  It is also readily agreed that
  42. this is done at some expense in terms of memory requirments,
  43. and also speed (especially in tight loops).
  44.  
  45. I went from the evolution from C to C++,  and feel that many
  46. of these problems can be easily solved if programmers just
  47. took advantage of the new features.  C++ can be safer.  For
  48. example, if you write (or buy) a good array class and use it
  49. instead of the standard types, then you will know longer have
  50. run away arrays.  Additionally, you can perform range checking
  51. or anything else.  For that matter, a heap class can be defined
  52. to handle garbage collection as well. Some have set let's compare
  53. languages as they are.  I recall when I read Lipmann's book
  54. that much of the addition of C++ was so that encapsulation could
  55. save the world from sloppy code.  So it is *fair* in my mind
  56. to say that on large projects which are inherently difficult to
  57. debug,  bound checking class be used de rigor.  However, in a tight loop
  58. you are free to use the standard types with no range or bounds
  59. checking.  Just be damn sure it is contained in a small block
  60. of code and that you don't screw it up. 
  61.  
  62.  It would seem to me
  63. that any language which incorporates range checking, bound
  64. checking, garbage collection, etc. from the get go loses the
  65. flexibility of higher performance in critical areas.  This may
  66. not be a problem for most projects since memory has become
  67. so cheap and computers so fast, but many people, particularly
  68. poor graduate students like me, would like their current
  69. hardrives and CPU RAM to hold out for a while.
  70.  
  71. I am always a few months/years behind on standards.  Are there
  72. standard container classes?  I think the standard "c" libraries,
  73. streams, and complex libraries, are not nearly enough.  Well
  74. implimented standard libraries for safer programming seems like
  75. a logical direction of evolution.
  76.  
  77. Mitch Dernis
  78.